<template>
  <view class="w100p common_wrap no-bg">
    <CommonHeader :title="$t('未接来电')" ></CommonHeader>
    <view class="tabs">
      <view :class="{tab: true,active: currentType == item.type}" v-for="(item,index) in tabList" :key="index" @click="onTap(item.type)">
        {{ item.title }}
        <view class="line"></view>
      </view>



      
    </view>
    <view class="w100p pr list_block">
      <scroll-view scroll-y @scrolltolower="loadMore" :scroll-top="scrollTop":scroll-y="true" @scroll="onScroll" >
        <view class="lists">
          <view class="list" v-for="(item,index) in list" :key="index">
            <!-- 询单信息 -->
            <view class="base-info" @click="goPerson(item)">
              <view class="left-avatar">
                <view class="avatar-w">
                  <view class="avatar">
                    <image :src="getImageUrl(item.avatar)" mode="aspectFill"></image>
                  </view>
                  <view class="country">
                    <image :src="createNational(item.country || 0).imgurl" mode="aspectFill"></image>
                  </view>
                </view>
                <view class="desc-avatar">
                  <view class="show">
                    <view class="name ellipsis_one">{{item[plangJava('callUserName')]}}</view>
                    <view class="vip-leval">
                      <view class="circle">
                        <image :src="memberLevel(item.level || 0).imgurl" mode="scaleToFill" />
                      </view>
                      <text>VIP</text>
                    </view>
                  </view>
                  <view class="start">
                    <uni-rate :value="item.rating" size="20" margin="8" activeColor="#FFE05F" color="#DBDBDB" readonly/>
                  </view>
                </view>
              </view>
            </view>
            <!-- 留言 -->
             <view class="message-bottom">
              <view class="left-liuyan">
                <view class="titme">{{item.createTime}}</view>
                <view class="info">{{ ['',$t('向您申请视频通话'),$t('向您申请视频通话'),$t('向您发送了一条留言')][currentType] }}</view>
              </view>
              <view class="btn" @click="onCall(item)">{{ ['',$t('发起视频通话'),$t('发起视频通话'),$t('前往聊天页面回复信息')][currentType] }}
              <image
								src="/static/translatexx.png"
								class="translatexxxxxx"
								mode="widthFix"
							/>
            
            </view>
            </view>
          </view>
            <!-- 升级vip -->
          <!-- <view class="model-vip">
            <view class="update">升级VIP</view>
            <view class="see">查看更多{{$t('询单信息')}}</view>
          </view> -->

          <u-empty :text="$t('暂无相关数据')" mode="order" v-if="!list.length" :margin-top="180"></u-empty>
        </view>
      </scroll-view>
    </view>



  </view>
</template>

<script>
import { faUnAcceptedList } from '@/api/online';
  import CommonHeader from "@/pages/components/common-header.vue";
  import { memberLevel,createNational } from '@/assets/public.js'
	import {  request_minute } from '@/api/basic'
	import { chechkIm } from '@/api/basic'

  export default {
    components: {
      CommonHeader
    },
    data() {
      return {
				scrollTop: 0,
        currentType: 1,
        pages: 0,
        page: 1,
        size: 20,
        list: [],
        tabList: [{
          title: this.$t('视频通话'),
          type: 1,
        },{
          title: this.$t('1v1预约'),
          type: 2,
        }],
      }
    },
    onLoad() {
      window.onNativeShow =  this.getData
      this.getData();
    },
    methods: {
      onScroll(e) {
        this.scrollTop = e.detail.scrollTop;
      },
      memberLevel,
      createNational,
         // getprolist 获取列表
      loadMore() {
        if(this.pages > this.page) {
          this.page++;
          this.getData();
        }
      },
    async getData() {
      uni.showLoading({
        title:'loading',
      })
        try {
          const res = await faUnAcceptedList({
            current: this.page,
            size: this.size,
            userId: uni.getStorageSync('user_id'),
            type: this.currentType,
          });
          this.pages = res.data.data.pages;
          // 首页置空数据
          if (this.page == 1) {
            this.list = res.data.data.records || [];
          } else {
            this.list = [...this.list, ...res.data.data.records]
          }
          uni.hideLoading()
        } catch (e) {
        }
      },
      onCall(info) {
        if (this.currentType == 1 || this.currentType == 2) { // 视频通话
          if(uni.getStorageSync("user_id") == info.callUserId) {
            uni.showToast({
              title: this.$t('不能给自己打电话'),
              icon: "none",
            });
          } else {
          
            request_minute({
              user_id: uni.getStorageSync("user_id"),
              target_id: info.callUserId,
            }).then(res => {
            if (res.data.data.flag == 1) {
              this.isMessageGo({
                action: 'call',
                data: {
                  userId: info.callUserId,
                  type: res.data.data.type || 1,
                }
              })
            } else {
              uni.$u.toast(this.$t('积分不足，请充值积分'))
              setTimeout(() => {
              	uni.navigateTo({
										url: '/pages/vip/scorePoint',
										webview: 'zWebView'
									})
              }, 500)
            }
          })
        }
        } else { // 聊天
          if(uni.getStorageSync("user_id") == info.callUserId) {
            uni.showToast({
              title: this.$t('不能和自己聊天'),
              icon: "none",
            });
          } else {
            this.isMessageGo({
              action: 'initiateChat',
              data: info.callUserId
            })
            return;
            chechkIm({
              send_uid: uni.getStorageSync("user_id"),
              receive_uid: info.callUserId,
            }).then(res => {
              if (res.data.code == 1) {
                this.isMessageGo({
                  action: 'initiateChat',
                  data: info.callUserId
                })
              } else {
                if (res.data.data.send_user == false) {
                  uni.$u.toast(this.$t('积分不足，请充值积分'))
                  setTimeout(() => {
                    uni.navigateTo({
                      url: '/pages/vip/scorePoint',
                    })
                  }, 500)
                } else {
                  uni.$u.toast(this.$t('对方积分不足'))
                }
              }
            })
          }


          // this.isMessageGo({
          //   action: 'initiateChat',
          //   data: info.callUserId,
          // })

        }
      },
      goPerson(item) {
        if (item.identityType == 0) {
        uni.navigateTo({
          url: `/pages/details/merchantDetail?bid=${item.shopId}`,
          webview: 'zWebViewShop'
        })
      } else {
        uni.navigateTo({
          url: `/pages/myPersonPage/index?targetUserId=${	item.callUserId}`,
          webview: 'zWebView'
        })
      }
      },
      onTap(type) {
        this.currentType = type;
        this.page = 1;
        this.list = [];
        this.scrollTop = 0;
        setTimeout(() => {
          this.getData();
        }, 300);
      }
    },
  }
</script>

<style scoped lang="scss">
  @import './index.scss';
</style>